<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />

    <a-card :bordered="false">
      <!-- <title-name title="设计资源列表" /> -->

      <div class="pub-table-select-count">
        <a-icon
          type="info-circle"
          theme="twoTone"
        />
        <span style="margin-right: 12px"> 设计资源总计 ：<span class="totalNum">{{ totalDels.total	}} 个</span> |
          A级设计资源：<span class="totalNum">{{ totalDels.designNumA }} 个</span> |
          B级设计资源：<span class="totalNum">{{ totalDels.designNumB	}} 个</span> |
          C级设计资源：<span class="totalNum">{{ totalDels.designNumC	}} 个</span>
        </span>
      </div>

      <list-table
        ref="table"
        bordered
        size="default"
        :row-key="record => record.id"
        :columns="columns"
        :request="loadData"
        :isScrollX="false"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a
              v-btnPermission="'ds_008_loo_01'"
              @click="handleDels(record,'view')"
            >查看</a>
            <a
              v-btnPermission="'ds_008_cha_02'"
              @click="handleEdit(record)"
            >等级变更</a>
          </MoreButton>
        </span>
      </list-table>


      <a-modal
        v-if="visible"
        width="900px"
        :visible="true"
        :title="titles"
        @cancel="visible=fasle"
      >
        <template slot="footer">
          <a-button
            key="back"
            @click="handleCancel"
          >
            取消
          </a-button>
          <a-button
            key="submit"
            type="primary"
            @click="handleOk"
          >
            确定
          </a-button>
        </template>
        <a-form :model="form">
          <a-row>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="设计资源名称"
                :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <BaseInput
                  v-model="form.name"
                  disabled
                />
              </a-form-item>
            </a-col>
            <a-col
              :md="12"
              :sm="12"
            >
              <a-form-item
                label="等级"
                :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
                :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              >
                <a-select v-model="form.resLevelId">
                  <a-select-option
                    v-for="item in levels"
                    :key="item.id"
                    :value="item.id"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </a-modal>
    </a-card>
  </base-breadcrumb>
</template>

<script>
  import { STable } from '@/components'
  import { getStatisticsTotal,getDesignResourcesList,addDesignResources } from '@/api/design/parameter'
  import { getTypes,getLabelTypes,getAllBranchCompany } from '@/api/commons'
  // import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司

  // import SelectProject from '@/components/Select/SelectProject' // 项目
  import OrgTreeSelect from '@/components/OrgTreeSelect'


  import ARow from 'ant-design-vue/es/grid/Row'

  const columns = [
    {
      title: '序号',
      width: '65px',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '设计资源名称',
      dataIndex: 'name'
    },
    {
      title: '分公司',
      dataIndex: 'branchName',

    },
    {
      title: '设计资源类型',
      dataIndex: 'resTypeName',
    },
    {
      title: '等级',
      width: '65px',
      dataIndex: 'resLevelName',
    },
    {
      title: '合作次数',
      width: '100px',
      dataIndex: 'coopNum',
    },
    {
      title: '入库时间',
      dataIndex: 'storeDate',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '220px',
      fixed:'right',
      scopedSlots: { customRender: 'action' }
    }
  ]

  export default {
    name:'a'+Date.now(),
    components: {
      ARow,
      STable,
    },
    data() {
      return {
        columns,
        titles:'等级变更',
        searchArr: [
          // 搜索框
          {
            name: '设计资源名称',
            value: 'designResourceName',
            type: 'input'
          },
          {
            name: '设计资源类型',
            value: 'resTypeId',
            type: 'select',
            data:[]
          },
          {
            name: '分公司',
            value: 'branchId',
            type: 'select',
            data:[]
          },
          {
            name: '等级',
            value: 'resLevelId',
            type: 'select',
            data:[]
          },
        ],

        visible:false,
        title:'',

        form:{
          resLevelId:''
        },
        forms:{},
        data:[],
        // 加载数据方法 必须为 Promise 对象
        queryParam:{},
        loadData: parameter => {
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          return getDesignResourcesList(requestParameters)
            .then(res => {
              return res
            })
        },
        selectedRowKeys: [],
        selectedRows: [],
        levels: [],
        totalDels:{},
      }
    },

    created() {
      this.getTypes()
      this.getStatisticsTotal()
      this.getAllBranchCompany()
    },
    computed: {
      // rowSelection() {
      //   return {
      //     selectedRowKeys: this.selectedRowKeys,
      //     selectedRows: this.selectedRows,   // 当前行所有数据
      //     onChange: this.onSelectChange
      //   }
      // }
    },
    methods: {
      // 分公司
      getAllBranchCompany(){
        getAllBranchCompany({tagCodes:['CO','BC']}).then(res=>{
          this.searchArr[2].data = this.getChangeDatatTypes(res.data)
        })
      },
      handleDels(record,type){
        this.$router.push({
          path:'/project/design/viewInvestigateByBook',
          query:{
            id:record.surveyId,
            type:type
          }
        })
      },
      getTypes(){
        getLabelTypes({type:13}).then(res=>{
          this.levels = res.data
          this.searchArr[3].data = this.getChangeDatatTypes(res.data)
        })

        getLabelTypes({type:14}).then(res=>{
          this.searchArr[1].data = this.getChangeDatatTypes(res.data)
        })
      },


      search(val){
        this.queryParam = val
        this.$refs.table.refresh(true)
        this.getStatisticsTotal()
      },

      handelAdd(){
        this.visible = true
        this.title='设计资源等级变更'
        this.form = {}
      },

      getStatisticsTotal(){
        getStatisticsTotal(this.queryParam).then(res=>{
          this.totalDels = res.data
        })
      },





      handleCancel(){
        this.visible = false
      },

      handleOk(){
        addDesignResources(this.form).then(res=>{
          if(res.code == 200 || res.data.code == 200){
            this.visible = false
            this.getStatisticsTotal()
            this.$refs.table.refresh(true)
          }
        })
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      handleEdit(record){
        this.visible = true
        this.form = {...record}
      },

    }
  }
</script>


